<?php
/****************************************
PAGE: engine/helpers/engine.helper.php
LAST MODIFIED: 25/09/09 14:37PM
BY: Franky
***************************************/

class EngageEngine extends EngageCore{
	
	function __construct(){
		$this->start_system_errors();
		$this->set_vars($_GET);
	}
	
	public function start(){
		session_start();
	}
	
	public function stop(){
		return true;
	}	
	
	public function load_module(){ 
		
		$file_exist = file_exists($this->site['module']['root']."start.php");
		
		if($file_exist){
			$file_exist = "";
			include($this->site['module']['root']."start.php");
			$load = new $this->site['module']['name'];
			$method = "_".$this->site['uri'][1];
			if(method_exists($load, $method)){
				echo $load->$method();
			}
		}
		
	}
	
	public function load_core_helpers(){
		
		$helpers_url = $this->site['root']."engine/helpers/";
		$helpers_dir = dir($helpers_url);
		
		while($helper_file = $helpers_dir->read()) {
			
			if ($helper_file == "." || $helper_file == ".."){
				$n = "";
			}else{
				if(strpos($helper_file, ".php") !== false){
					$helper_url = $this->site['root']."engine/helpers/".$helper_file;
					if (file_exists($helper_url)) {
						include($helper_url);
					}
				}
			}
			
		}
		
		$helpers_dir->close();
	}
	
	public function load_plugins(){
		
		$modules_dir = dir($this->site['modules']['root']);
		
		while($folder = $modules_dir->read()) {
			
			if ($folder == "." || $folder == ".."){
				$n = "";
			}else{
				$plugin_url = $this->site['modules']['root'].$folder."/plugin/start.php";
				if (file_exists($plugin_url)) {
					include($plugin_url);
				}
			}
			
		}
		
		$modules_dir->close();
		
		$interface_plugin = $this->site['interface']['root']."plugin/start.php";
		if(file_exists($interface_plugin)){
			include($interface_plugin);
		}
	}
	
	protected function start_system_errors(){
		$_SESSION['e__sys_errors'] = array();
	}
	
	public function parse_system_errors(){
		
	}
}
?>